How to change Asp.net .cs file path - asp.net

I am newbie with asp.net. I'm using Visual Studio 2022 to write my codes. How can I change the ".cs" file location ? because I need to send my application to someone else. The issue starts when I put ".cs" file in a 1 folder. When ".cs" file on my desktop the application works.

I find a solution for this problem.
Do this following steps :
1)Go to the file which appears as Miscellaneous Files inside Solution Explorer.
2)Right-Click file and select Exclude from project.
3)Right-Click your project/folder where the file was and click add Existing Item, and add the file you just removed back into your project

Related

PDF is not accessible through URL in IIS .NET Framework 4.8 app

I have a PDF file in a folder on a server within a IIS website app that I need to be able to open through a link/url, like below:
https://api.example.com/my-path/my-pdf-file.pdf
The PDF file is hosted in a folder of my IIS application. When I try to access it through the link, I've got a 500 server error.
I tried several things within IIS settings (URL Rules, web.config, mime-types), but nothing worked so far.
Any advice will be much appreciated.
Is the folder included in the project? You can't just add a folder outside of Visual Studio, but have to use VS to add that folder.
You can right click on that existing folder (which of course is a sub folder of your project) and check this setting:
So, in my case, I right click on UpLoadFiles.
If the folder ALREADY is included in the project, then you get a option to EXCLUDE the folder like this:
However, if the folder is not included, then you see this:
so, is that folder included in your project? You want to check above.

How to handle path on azure for XmlDocumentationProvider

I am using azure for deployment of my new Web API's, I am new with deployment on IIS and azure.
I have added my Web API's on azure as web application, and it's working fine, till I added documentation for each API's functions. After adding description I uncomment line below from HelpPageConfig.cs.
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));
It's working finr locally, and I am able to see all descriptions, but when I published it on azure, I am getting error saying,
Could not find a part of the path 'D:\home\site\wwwroot\App_Data\XmlDocument.xml'.
site url : http://mejodo.azurewebsites.net/
Do I need to change path ?
File is already created in my system on D:\home\site\wwwroot\App_Data directory.
What changes I need to do to make it work ?
I had the same issue. For me the file was generated. Please follow the below steps.
Click on show all files in solution explorer.
Check whether you have a file in App_Data folder
If you have the file, right click and include the same in your project.
Now build and publish to Azure.
I hope this will work. Thanks
In my case XmlDocument.xml had to be added in Visual Studio to the App_Data folder within the solution using 'add existing item'.
Just add to your project new folder "App_Data" with XmlDocument.xml and publish
When you say that you have Web API's on azure as web application, do you mean that they are applications under the site ? If yes, then I think you are missing the application name in the path to the XML file.
Try going to mejodo.scm.azurewebsites.net > debug console > powershell to see the exact folder structure....
You must verify that the line in the HelpPageConfig.cs file in the Area>HelpPage>App_Start folder.
that is in the register method, this line is
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));
this uncommented
then you must verify that in the project configuration, in the build XML documentation file, this is the same path as the above mentioned line.
When you publish the xml file goes in the bin folder, so change 'D:\home\site\wwwroot\App_Data\XmlDocument.xml'.
to
'D:\home\site\wwwroot\bin\XmlDocument.xml'.
and it should work.

Adding global.aspx file

I am currently using IIS to host a simple website, and would like to know how to enable the 'Global.aspx' file? I need to know where I would define it, as all the tutorials talk about using Visual Studio, which I am not using.
File Global.asax should be placed on the root directory of your site. There is nothing else to do besides adding required code, you put it there and just work.
Just right-click on the project name displayed in the Solution Explorer, and choose Add New..., then choose Global.asax from the list displayed in the new popup window. It goes to the root of your application.
Here is further information: Where is the Global.asax.cs file?

ASP.net This is a marker file generated by the precompilation tool, and should not be deleted

I am currently getting this when visiting my http:// websitehere.com/excelData.aspx page:
This is a marker file generated by the precompilation tool, and should not be deleted!
The file system directory on the server looks like this:
--mainDir
|--excelData.aspx
|--PrecompiledApp.config
|--Web.config
|--bin
|--App_Web_cuydkh1j.dll
|--exceldata.aspx.cdcab7d2.compiled
Not sure what I need to add/remove in order for it to display my page without that precompilation tool text on it.
The IIS server is version 6.1
One of the reasons for this problem is the file PrecompiledApp.config is missing from the root of your site (this file is generated by the publishing wizard).
Hope this help others.
Problem:
When you upload the web application, sometimes the most important files in the bin folder (e.g., the .dll files) will not upload correctly.
Solution:
Re-upload the bin folder. Remember to overwrite.
Make sure the site is configured as an application on IIS

how to edit a file in an online aspx site?

I'm very new to asp.net ( but an aged PHP developer) ..
I'm now in a situation where I should do some small modification in an online aspx script(using vb.net).
I downloaded the whole site and opened it in visual studio, all the modification I had to do is to make a redirect to another external page after succesful login,I determined the place where I should do my modification inside a file named login.aspx.vb , and added this line in it:
Response.Redirect("My URL Here")
And then uploaded only the modified file again, to get no change at all.
I even tried to modify the success msg that appear after successful login and re-uploaded it to find no change at all ( still showing the old message)
Is there some step I'm missing before uploading the page?
You will need to compile the project, and if using visual studios you can just hit ctrl shift B and it will build the entire solution. Visual studio detects which project in the solution has changed and will compile it. Then do as the other answerer says and upload the .dll file which is a container of your compiled code that will be referenced by the host you upload it to when there is a request for it. (A container is a definite over simplification for more details check:
What is a dll?
In ASP.NET there are two types of projects.
Web application project
Web site project
In the first case, when you edit a .vb file you need to compile it with Visual Studio and upload the generated .dll file created in the bin folder.
In the second case you can edit the .vb files and upload them and IIS will compile them.
Based on what you wrote, you are in the first case. In that case you need to have the project / solution files to make any modifications in the .vb files. If you don't have access to those files you could inject some code in the .aspx or .ascx files.
For example:
<%
Dim flag As Boolean = false
// Write some code to set the flag
If (flag) Then
Response.Redirect("~/default.aspx")
End If
%>
Using <%....%> you can write code to execute when the page starts to render. This is a bad practice since because it has poor performance since the code is parsed and executed at runtime, while the code in .cs files is already compiled.
But if you don't have the project files you could do minor changes with this hacky approach.
Edit: If you are in the first scenario, you need to build the project and then upload its .dll file which is in the /bin folder. For any changes in the code files you upload only the .dll. If you change the .aspx, .ascx, etc files you need to upload those as well

Resources