ASP.NET - FAQ (Preguntas Frecuentes)
- Ingles |
General FAQs
Business Objects-related
FAQs
General FAQs
Q: Why do I not see
detailed error messages when I have an error in my ASP.NET page?
I only see information about a generic runtime error like the following:
Server Error in '/appname' 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.
Details: To enable
the details of this specific error message to be viewable on the
local server machine, 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 "RemoteOnly". To enable the
details to be viewable on remote machines, please set "mode" to
"Off".
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="RemoteOnly"/>
</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="On"
defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
A: By
default, ASP.NET applications are configured with custom error messages
turned off. However, some web development tools, such as Visual
Studio.NET, will create a web.config file with the customErrors
mode set to “RemoteOnly”. In order to enable detailed error
messages, you need to make sure that you either remove the customErrors
section in your web.config file or that you set the mode attribute
in the customErrors section to “Off” in your site’s web.config file.
<customErrors mode="off"/>
Be aware that when you set
the customErrors mode to “Off” all visitors of your web site will
see the detailed error message.
Note that due to the nature of the shared hosting platform the “RemoteOnly”
and “On” modes of the customErrors section are equivalent since
every visitor to your web site is browsing remotely.
_______________________________
Q: Why do I receive an error like the following
when I attempt to browse my ASP.NET page?
Server Error in '/appname' 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='MachineOnly'
beyond machine.config.
A: You may have defined a section
in your application’s web.config file that is not configurable on
our shared web hosting platform. Remove or comment out any
configuration sections from your web.config file that are not supported.
See Supported Configuration Options for more information.
___________________________
Q. Which ASP.NET configuration options are supported
in the ASP.NET implementation on the shared web hosting platform?
A: Many of the ASP.NET configuration
options are not configurable at the site, application or subdirectory
level on the shared hosting platform. Certain options can
affect the security, performance and stability of the server and,
therefore cannot be changed. The following settings are the
only ones that can be changed in your site’s web.config file(s):
browserCaps
clientTarget
pages
customErrors
globalization
authorization
authentication
webControls
webServices
See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconaspnetconfiguration.asp
for information on ASP.NET.
_____________________________
Q: Are
CodeBehind pages supported?
A: Yes, CodeBehind pages are supported in our shared
web hosting platform. For more information on CodeBehind and
the ASP.NET Web Form architecture, please see http://msdn.microsoft.com/library/en-us/cpguide/html/cpconwebformscodemodel.asp?frame=true
__________________________
Q: How do I send an email message from
my ASP.NET page?
A: You can use the System.Web.Mail.MailMessage and
the System.Web.Mail.SmtpMail class to send email in your ASPX pages.
Below is a simple example of using this class to send mail in C#
and VB.NET. In order to send mail through our mail server,
you would want to make sure to set the static SmtpServer property
of the SmtpMail class to mail-fwd.
C#
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Mail" %>
<HTML>
<HEAD>
<title>Mail Test</title>
</HEAD>
<script language="C#" runat="server">
private void Page_Load(Object sender, EventArgs e)
{
try
{
MailMessage mailObj = new MailMessage();
mailObj.From = "sales@joeswidgets.com";
mailObj.To = "ringleader@forexample-domain.com";
mailObj.Subject = "Your Widget Order";
mailObj.Body = "Your order was processed.";
mailObj.BodyFormat = MailFormat.Text;
SmtpMail.SmtpServer = "mail-fwd";
SmtpMail.Send(mailObj);
Response.Write("Mail sent successfully");
}
catch (Exception x)
{
Response.Write("Your message was not sent:
" + x.Message);
}
}
</script>
<body>
<form id="mail_test" method="post"
runat="server">
</form>
</body>
</HTML>
VB.NET
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Mail" %>
<HTML>
<HEAD>
<title>Mail Test</title>
</HEAD>
<script language="VB" runat="server">
Sub Page_Load(sender As Object, E as EventArgs)
Try
Dim Mailer As MailMessage
Mailer = New MailMessage()
Mailer.From = "sales@joeswidgets.com"
Mailer.To = "ringleader@forexample-domain.com"
Mailer.Subject = "Your Widget
Order"
Mailer.Body = "Your order was
processed."
Mailer.BodyFormat = MailFormat.Text
SmtpMail.SmtpServer = "mail-fwd"
SmtpMail.Send(Mailer)
Response.Write("Mail sent successfully")
Catch ex As Exception
Response.Write("Your message
was not sent: " + ex.Message)
End Try
End Sub
</script>
<body>
<form id="mail_test" method="post" runat="server">
</form>
</body>
</HTML>
___________________________
Q: How do I upload
a file from my ASP.NET page?
A: In order to perform file upload in your ASP.NET
page, you will need to use two classes: the System.Web.UI.HtmlControls.HtmlInputFile
class and the System.Web.HttpPostedFile class. The HtmlInputFile
class represents and HTML input control that the user will use on
the client side to select a file to upload. The HttpPostedFile
class represents the uploaded file and is obtained from the PostedFile
property of the HtmlInputFile class. In order to use the HtmlInputFile
control, you need to add the enctype attribute to your form tag
as follows:
<form id="upload"
method="post" runat="server" enctype="multipart/form-data">
Also, remember that the /data
directory is the only directory with Write permissions enabled for
the anonymous user. Therefore, you will need to make sure
that the your code uploads the file to the /data directory or one
of its subdirectories.
Below is a simple example of
how to upload a file via an ASP.NET page in C# and VB.NET.
C#
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.UI.HtmlControls" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Drawing" %>
<html>
<head>
<title>upload_cs</title>
</head>
<script language="C#" runat="server">
public void UploadFile(object sender, EventArgs e)
{
if (loFile.PostedFile != null)
{
try
{
string strFileName, strFileNamePath,
strFileFolder;
strFileFolder = Context.Server.MapPath(@"data\");
strFileName = loFile.PostedFile.FileName;
strFileName = Path.GetFileName(strFileName);
strFileNamePath = strFileFolder
+ strFileName;
loFile.PostedFile.SaveAs(strFileNamePath);
lblFileName.Text = strFileName;
lblFileLength.Text =
loFile.PostedFile.ContentLength.ToString();
lblFileType.Text = loFile.PostedFile.ContentType;
pnStatus.Visible = true;
}
catch (Exception x)
{
Label lblError = new
Label();
lblError.ForeColor =
Color.Red;
lblError.Text = "Exception
occurred: " + x.Message;
lblError.Visible = true;
this.Controls.Add(lblError);
}
}
}
</script>
<body>
<form id="upload_cs" method="post" runat="server" enctype="multipart/form-data">
<P>
<INPUT type="file" id="loFile" runat="server">
</P>
<P>
<asp:Button id="btnUpload" runat="server" Text="
Upload " OnClick="UploadFile"></asp:Button></P>
<P>
<asp:Panel id="pnStatus" runat="server" Visible="False">
<asp:Label id="lblFileName" Font-Bold="True" Runat="server"></asp:Label>
uploaded<BR>
<asp:Label id="lblFileLength" Runat="server"></asp:Label>
bytes<BR>
<asp:Label id="lblFileType" Runat="server"></asp:Label>
</asp:Panel></P>
</form>
</body>
</html>
VB.NET
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.UI.HtmlControls" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Drawing" %>
<HTML>
<HEAD>
<title>upload</title>
</HEAD>
<script language="VB" runat="server">
Sub UploadFile(sender as Object, e as EventArgs)
If Not (loFile.PostedFile Is Nothing)
Then
Try
Dim strFileName,
strFileNamePath, strFileFolder As String
strFileFolder
= Context.Server.MapPath("data\")
strFileName
= loFile.PostedFile.FileName
strFileName
= Path.GetFileName(strFileName)
strFileNamePath
= strFileFolder + strFileName
loFile.PostedFile.SaveAs(strFileNamePath)
lblFileName.Text
= strFileName
lblFileLength.Text
= loFile.PostedFile.ContentLength.ToString()
lblFileType.Text
= loFile.PostedFile.ContentType
pnStatus.Visible
= True
Catch ex As Exception
Dim lblError
As Label
lblError
= New Label()
lblError.ForeColor
= Color.Red
lblError.Text
= "Exception occurred: " + ex.Message
lblError.Visible
= True
Page.Controls.Add(lblError)
End Try
End If
End Sub
</script>
<body MS_POSITIONING="FlowLayout">
<form id="upload" method="post" encType="multipart/form-data"
runat="server">
<P><INPUT id="loFile" type="file" name="loFile" runat="server">
</P>
<P><asp:button id="btnUpload" onclick="UploadFile" runat="server"
Text=" Upload "></asp:button></P>
<P><asp:panel id="pnStatus" runat="server" Visible="False">
<asp:Label id="lblFileName" Runat="server" Font-Bold="True"></asp:Label> uploaded<BR>
<asp:Label id="lblFileLength" Runat="server"></asp:Label>bytes<BR>
<asp:Label id="lblFileType" Runat="server"></asp:Label></asp:panel></P>
</form>
</body>
</HTML>
Business Objects-related FAQs
Q: To which directory are business objects (compliled
DLLs) uploaded?
A: Each ASP.NET application (web sites are now referred to
as applications - child webs, etc....) is automatically configured
to look in the \bin subdirectory, located immediately under your
application root, for the required .NET assemblies. By default,
the root of your site is an application. Remember, using certain
tools such as Visual Interdev or Visual Studio.NET, you can create
more than one application on your site. Each application would
need its own \bin directory. If you are using Visual Studio.NET,
your application (and its \bin directory) will be created automatically
when you create a new web project in a subdirectory of your site.
Q: Are these business objects compiled?
A: The simple answer is on the client side. If you
are using VB.NET and VisualInterdev, the objects are compiled and
uploaded automatically. These processes are transparent to the user.
If a command line compiler is used, then the client must upload
the object to the /bin directory of the root application or
application subdirectory.
Q: Is there
any change to the global.asax file?
A: No, it is the same as the global.asa found today.
.NET does, however, introduce a new file called "web.config"
to set parameters for your site.
Ultima modificación: 02/11/2002.
|