iis and asp.net mvc compilation - c#

as project is in developing state uploaded Files on webserver has not been compiled for easy editing and other reason , when i edit model and add property to view , iis say that your model has no that because of old compilation files , solution that Tested :
Deleted Temp folder in windows\microsoft.net
<compilation batch="false" debug="true" targetFramework="4.5" />
add new line to webconfig to force new compile
yet it run old compiled files

Based on the comments, I will add an answer...
You need to actually publish the application: How to publish a web app. You can publish this locally on your desktop and copy the files onto the server, or you can publish direct to your server.
When you publish the application, the model(s) get compiled into an assembly in your bin folder, so you cant directly modify these files on the fly.
You can chose a setting to allow for views to be updated, but this is very limited.
So, best approach is to set up a publish profile for your DEV server, and make your change, and then re-publish. It will take you less than a minute to get the latest code on the server.

Related

Build ASP.NET Web Api to a different output directory

I have a ASP.NET web api project, the api has lot of dependencies to other dlls so we have placed all the dlls in a specific folder. If I point output path of the web api to that output directory and execute in IISExpress it gives following error
Parser Error Message: The CodeDom provider type "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" could not be located.
If we see file location of the error it is still pointing to WebAPI_SourceCode_Directory\web.config and not my output folder. But output folder has web.config file. How can I make the web app to run from output folder using IISExpress
It is not recommended to change the output directory of an asp.net application due to IIS security restrictions.
However you can still hack your way through it by changing config files appropriately, see here
As per MSDN article, when you compile a Web application the compiled code is placed in the Temporary ASP.NET Files folder
To find this Temporary ASP.NET Files folder check my post here
do not use IIS express for development, use a proper IIS instead. This way you will iron out any production issues from the beginning.
Whether your API has a lot of dll dependencies or not, it makes no difference. The API needs to know where to get them from and I wouldn't change the default behavior. They will be in the bin folder like all the other dependencies when you build the project.
To deploy the API even in a local environment, use the Publish method to a local folder, then build an IIS application pointing to that folder.
That's all you need to do, so why complicate things? You can still publish in debug mode, you can still connect your Visual studio to it and debug it properly. There is literally zero need to fight the default way of doing things.

Config file for publishing web service

I have a Visual Studio web service application with the following solution structure (using VS2013 Community):
- [Solution] S
- [Project] S_Service
- S.amsx
- [Project] S_Lib
- File1.cs
- File2.cs
- app.config
The S_Service project is a simple web service project, with just a single asmx file with one WebService method. The project contains a reference to the S_Lib project, a class library to do all the work in terms of the business logic (the request processing).
In S_Lib I have an app.config file in which I store things like directories and file names for stuff which is used by the various components in S_Lib. When I am developing, changes to that file are picked up by the code ok.
Here's the problem: When I publish the S_Service project, the publish directory doesn't contain my app.config - only S_Service.dll and S_Lib.dll. After reading some other posts on StackOverflow (can't seem to find them now), I tried setting the build action on app.config to Content and to Copy Always. Great, this gets the file across to the publish directory, so it looks ok. But, once I deploy the whole lot onto IIS, any changes to the app.config file do not get reflected when the service is run. In fact I can delete the file completely from the IIS directory and it runs just fine. It's as though S_Lib.dll contains a compiled version of the configuration settings. This is no use, as I want to modify the config depending on the machine it's deployed on.
What do I need to do so that app.config is actually used at runtime and that changes are read on the fly?
Just as you wrote, S_Lib.dll contains compiles settings from the time when you set them in VS settings designer. Therefore it is still working (more or less).
You have a web service so you need a web.config. Add one to S_Service project. Then merge app.config content to web.config. Every time you change some setting in S_Lib project you will have to merge changes to web.config as well.
Or you could add app.config to S_Service project as a link by name web.config (not sure if it is possible to create a link with different name). Then when you change settings in S_Lib project they will be referenced in S_Service project automatically.
After failing to find a simple Visual Studio-based solution to do what I want, I implemented a more customised solution. In the library project, I replaced the config lookup method:
internal static string GetConfig(string key) {
return ConfigurationManager.AppSettings[key] as string;
}
with a new method that reads my own settings file (custom format), stored in the solution. It's not perfectly ideal as it means that each project in the solution has to have its own settings file, but it's simpler overall. If anyone is interested please leave a comment and I will elaborate on this solution.

app_code files not found by the project

my name is samy and im going insane!
i got this problem that my class's in app_code are no visible afther im uploading them to the server.
localy every thing work fine.
i read some other qustions on this when a lot of answer were like this:
"Right-click on the item in the solution explorer, and select Properties. In the properties window, there is a Build Action option."
*when i right click i cant see any proprty button so i used F4 but then i cant see any build option only "Custom Tool", "File Name" , "Full Path".
and
"you need to publish your website first."
*this didnt work either.
or
"your class are not compiled.
*i tried to build solution and that didnt work either.
please help me becuse im starting read/see tutorials on how to make a good rope knots (this will probly fails too so dont worry to much lol)
this is the error im getting (its look like this becuse im using iframe)
http://img14.imageshack.us/img14/11/theerrorb.png
this is error i get if i publish the site and upload it to the server all the app_code files are compiled in the bin folder as you said.
http://img193.imageshack.us/img193/4436/errorifipublish.png
Possible Solution 1
I have seen this before when working with ASP.NET Web Sites. If my memory serves me right, you should make sure that the paths to your references are wired up correctly.
i.e. if you added a custom DLL to your project
C:\My References\Some3rdParty.dll
and you moved the DLL to another folder/location. Or you could simply have a reference to a DLL that cannot be found.
If you resolve these reference problems you could find that your App_Code gets compiled all of a sudden.
Possible Solution 2
Right click and go to the properties of each of the .cs files in your App_Code directory in the Visual Studio Solution Explorer and make sure that the Build Action is set to Compile.
Possible Solution 3
If you have your .cs files in sub-folders within the App_Code directory you should add the following to your web.config file:
<configuration>
<system.web>
<compilation>
<codeSubDirectories>
<add directoryName="MySubAppCodeFolderName"/>
</codeSubDirectories>
</compilation>
</system.web>
</configuration>
Possible Solution 4
In Visual Studio, right-click on your Web Site in the Solution Explorer and click Publish Web Site. Make sure that the Target Location is a folder on your machine.
Log-in you your web-server and go to the BIN folder there. In the BIN folder on your web site delete all of the App_Web_.dll and App_Web_.dll.compiled files.
From your machine, copy your web site (including the App_Web_*.dll's in the BIN) to your web server where your web site is located. The only file you should probably not copy across is your Web.config file.

Build (and Debug) ASP.NET Web Application in a non-default folder location

I have a Visual Studio 2008 solution with an ASP.NET Web Application project. I want to change the default output folder, of said project, to $(SolutionDir)\WebApps\$(ProjectName)\bin. This I can do and when I build I get the expected assembly files in this folder. It doesn't copy the content files (aspx, etc.) to the parent folder but I have managed to fix this by hacking the project.csproj file with a custom build target.
The problem is I want to be able to debug this application using the ASP.NET Development Server, by pressing F5 in VS2008. Unfortunately the ASP.NET Dev server starts, has a "Physical Path", in the project directory rather than the parent of the output directory.
Is there any way to build my web application to a different output folder but still run the asp.net dev server to debug my site?
Thanks.
Short answer is yes, but it isn't pretty. The process I used is given below.
Unloaded the project in VS.
Manually edited the .csproj file to include a post build action that basically copies the content files (aspx, etc.) to the parent of the output folder.
For the debug options I set the project to launch an external executable. The Asp.Net Development server. Also manually set the url to launch.
What I learnt? I wouldn't do this, I'd just stick with the default and create an install/web deployment project instead.

referencing dotnetnuke.dll from another folder on asp.net

I have dotnetnuke portal on server in /root/dnn and I am creating asp.net app in c# VS2008 that I need to upload on /root/app.
when I deploy my app, it needs to reference dotnetnuke.dll assembly from /root/dnn/bin instead of /root/app/bin.
how can I manage that, without putting app files in /root/dnn?
I tried to set auto-refresh path and then after upload deleting the /root/app/bin/dotnetnuke.dll so that the app tries to reference the missing assembly in ../dnn/bin/dotnetnuke.dll but the "application is not pre-compiled" error pops, so I tried to upload it without pre-compiling, but still the reference couldn't be found.
Why not give your app it's own copy? That would solve all problems...
In other words, why the cross-app reference? It goes against all security mechanisms of IIS and ASP.NET
As Purple Ant said above, either
load the DotNetNuke assembly into the GAC (which is troublesome because it precludes you from being able to XCOPY upgrade DNN later)
Put your app into the DNN application folder (sounds like what you did)
Copy the DNN dll into your app folder. (the most common solution)
What you're thinking of is the <probing privatePath="" /> element of the config file. But I don't think it's available to be used in web apps and (according to the documentation) only works for subfolders.
<configuration>
<runtime>
<assemblyBinding>
<probing privatePath="bin;bin2\subbin;bin3"/>
</assemblyBinding>
</runtime>
</configuration>
After all, I had to upload .aspx and .aspx.cs files in portal folder and bin files in dnn's bin folder, add the few lines from my web.config to dnn's web.config, and change queries to database by writing them from code instead using dataset objects, that is .xsd, .xss files. I also had to copy the code from my App_Code into my .cs files before upload because C# and VS cannot be compiled together in dnn's App_Code.
I think your best bet with what you are trying to do is to install the DotNetNuke.dll into the GAC on the server. I don't believe that ASP.NET/IIS will allow access to any assemblies outside of the current websites folder structure.

Categories