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?
Related
I am setting up a blank project in Visual Studio 2012 and have set my index.html as the start page. The problem I am having is that the URL now says "localhost:64237/app/index.html" as it is including the path to the index page.
I want to be able to type in "localhost:64237" and have it still access the index page, without showing me the rest of the path or the filename/extension in the URL.
Right-click the project and go to properties. Select "web" on the left-hand side. Under the "servers" section, you should be able to set it up with out "app". Once that's done, it should work like you want. If not, look into IIS and Virtual Directories.
You can use routing.
By using routing you can change this:
http://www.mywebsite.com/Product/ProductDetails.aspx?id=1
http://www.mywebsite.com/ProductProductDetails.aspx?name=Apple
into this:
http://www.mywebsite.com/Product/1
http://www.mywebsite.com/Product/Apple
or this:
http://www.mywebsite.com/Apple
Find more info in google about ASP.NET Routing.
good luck
In my project the Global.asax file is removed. I want add a global.asax file to my projet.
But in Add New Item dialog the Global.asax not exist.
Just in case you may have missed the item even though it may actually be there for you I'll post this answer.
In Visual Studio 2013
Open Solution Explorer.
Right-click on the project.
Add New Item.
VB or C#
Web.
General.
Global Application Class.
Create an empty new project.
Go to that folder and copy the Global.asax file.
Go to your project and in solution explorer paste it on root.
Open Global.asax file and change namespace match to your namespace.
In solution explorer right click on Global.asax and pick View Markup and change inherits match to your namespace.
Any problem doing this:
Create a new empty project and get it from there (drag-and-drop from Windows Explorer to Visual Studio works fine), or
Add, say aspx page or any item, then rename accordingly (to get the code behind file, add and rename another item); in this case, they'll obviously be empty.
I've been trying to publish my Visual Studio 2010 project. I do this by accessing a hard drive which corresponds to a URL, so X:\Options\Forms\HD\ corresponds to /HD. Yet when I go to the URL, it says I don't have a default.aspx page. Yet when I look in the corresponding file directory the default.aspx page is right there. Why is the browser ignoring it? Another issue I have is that not all of the files are getting published when I select the option in Visual Studio; many are left behind including my default.aspx.vb file.
To make sure files get published, make sure that they have the correct Build Action set (check the Properties window for the file). Especially, if it is set to None or if the files are not part of the solution/project they won't get published. The "Content" build action is a good choice for any file that just needs to be published.
Extra tip: for files that VS doesn't know the default build action is None. You can however configure VS to use whatever build action you want.
I've written about it here: http://blog.andreloker.de/post/2010/07/02/Visual-Studio-default-build-action-for-non-default-file-types.aspx
Also, I've created a simple tool that generates the necessary configuration file: http://tools.andreloker.de/dbag
So, I've created my wonderful winforms app that I want to unleash upon the world, and now I am trying to create a simple website to host some basic information and link to the setup file (msi installer file )....
I have a button on the asp.net page and the setup file setupApp.msi in same folder as the asp.net page. I am currently trying the following:
Response.Redirect("http://./SetupApp.msi");
But this best guess at what to do is not working. Is there something wrong with Mime types here? What do I need to put in the click event to allow users to download this file?
The path you are passing in to the method is not valid (there's no server name called ".").
You can pass in a relative path and it should work fine because ASP.NET will resolve the path:
Response.Redirect("SetupApp.msi")
Or if it's not in the same folder, try one of these:
Response.Redirect("../Downloads/SetupApp.msi")
Response.Redirect("~/SomeFolder/SetupApp.msi")
Keep in mind that you don't necessarily have to do the whole redirect at all. Instead of writing code in an ASPX file you could just have a link to your MSI:
Download my app!
I created a C# web project with MSVS 9 and thats all i know about my configurations.
In my browser i can access any aspx files i have in my project. However when i use http://localhost:3288/img/test.png i see nothing. The working directory is ./root, the png file is in ./root/img/test.png How do i have ASP.NET display my images and everything else in the folder? (and subfolders).
Is the .png included in the solution?
When you hit the "play" button your essentially starting up a new website ( localhost:2383 ) so if its not in the solution it won't be copied over to the new, temporary, website that the debugger attaches too.
If this is the problem a quick fix is to hit the "Show all Files" button on the top of your solution explorer, this will show all the files in that folder on your hard drive. Then right click on the .png you want to include and hit "Include in Project".
Based on your comment your only solution is to actually create an IIS site for your solution with the root dir the same as your web project. Then in the project properties you'll have to tell the debugger to attach to your local IIS instead of visual studios. Not sure the exact click path, right click on your project and go to properties, look for debugging options.
Give a look to the ASP Image control , you can specify paths starting in your app root (~):
<asp:Image id="Image1" runat="server"
ImageUrl="~/Images/image1.png"/>
Or you can use relative paths to the page that are displayed.
Check this article about ASP .NET Website Paths.