Graviton
Graviton

Reputation: 83254

View ASPX page in Web browser

I have the following .aspx page, and I want to view it in web browsers such as IE or Google Chrome by opening it directly in those browsers:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    </form>
</body>
</html>

But somehow the browsers can't render it. In IE, the error is

Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later. A name was started with an invalid character. Error processing resource 'file:/

 <%@ Page Language="C#"AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %> -^*

What did I do wrong?

Upvotes: 2

Views: 23709

Answers (3)

Voicu
Voicu

Reputation: 17850

Recent Visual Studios (at least 2010+) have a new feature called View in Browser which you can run on an .aspx file. Please note that, as per documentation, debugging breakpoints are not in effect even if debugging is enabled.

Right click the file in the Solution Explorer or the Editor and then select View In Browser (your default browser here).

Keyboard shortcut: Ctrl+Shift+W

Upvotes: 1

seanb
seanb

Reputation: 6954

It won't actually work properly unless it is "served" by a web server of some sort.

If you are using Visual Studio, fire up the debugger, which by default will open IE, then grab the url from the location bar, and paste that into the browsers you want to check. Elsewise, mount the web site in IIS, and browse it that way.

Just opening the source file in a browser probably won't give you the result you are looking for.

Upvotes: 1

Brettski
Brettski

Reputation: 20081

Remove or comment out the

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>

line as a browser doesn't know what to do with it. This is normally interpreted by iis and not sent to the browser.

Upvotes: 3

Related Questions