Im having some strange trouble.
I have a piece of code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>VERSIONS CHECK!!!</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblVersion" runat="server" />
</div>
<br />
<div>
<asp:Label ID="lblHelloWorld" runat="server" />
</div>
<p>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</p>
</form>
</body>
</html>
and the codebehind file:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default开发者_Python百科 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblVersion.Text = System.Environment.Version.ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
if (lblHelloWorld.Text.Equals(string.Empty))
{
lblHelloWorld.Text = "Hello World";
}
else
{
lblHelloWorld.Text = "";
}
}
}
This works both locally, and in my public_html folder. But if I put the same in subfolders, like public_html/folder1/folder2
it comes with an error.
Server Error in '/' Application.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
Im brand new to ASP.NET and publishing with visual studio - so chances is that im doing something wrong somewhere. Actually this is my first attempt on writing ASP.NET - so be gently :)
Thx in advance.
Jack this is how my config file looks now:
Asp.Net Configuration option in Visual Studio. A full list of settings and comments can be found in machine.config.comments usually located in \Windows\Microsoft.Net\Framework\vx.x\Config -->
<system.web>
<compilation debug="true" targetFramework="4.0">
</compilation>
<authentication mode="Windows"/>
<customErrors mode="Off" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
</configuration>
And the error i get now is:
Server Error in '/' Application. Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.
Source Error:
Line 26: ASP.NET to identify an incoming user.
Line 27: -->
Line 28: <authentication mode="Windows"/>
Line 29:
Line 30:
Do you have a web.config
file in the sub-directory? If so, are your setting the authentication mode
in that sub-directory web.config?
You can't set the authentication mode from a sub-directory: ASP.NET Configuration File Hierarchy and Inheritance
Well to figure out what error you are receiving, you need to see customErrors to "Off" in your web.config file. You could set it to RemoteOnly but I don't think you're viewing it on the actual server box, so set it to off.
<customErrors mode="Off" defaultRedirect="GenericErrorPage.htm">
</customErrors>
That will show you what error you are receiving.
精彩评论