返回首页

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

 

public partial class Product : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        // Retrieve ProductID from the query string

        string productId = Request.QueryString["ProductID"];

        // Retrieves product details

        ProductDetails pd = CatalogAccess.GetProductDetails(productId);

        // Does the product exist?

        if (pd.Name != null)

        {

            PopulateControls(pd);

        }

        else

        {

            Server.Transfer(" /NotFound.aspx");

        }

        // 301 redirect to the proper URL if necessary

        Link.CheckProductUrl(Request.QueryString["ProductID"]);

    }

 

    // Fill the control with data

    private void PopulateControls(ProductDetails pd)

    {

        // Display product details

        titleLabel.Text = pd.Name;

        descriptionLabel.Text = pd.Description;

        priceLabel.Text = String.Format("{0:c}", pd.Price);

        productImage.ImageUrl = Link.ToProductImage(pd.Image);

        // Set the title of the page

        this.Title = PoshandDanglesConfiguration.SiteName + ": " + pd.Name;

 

        // obtain the attributes of the product

        DataTable attrTable =

          CatalogAccess.GetProductAttributes(pd.ProductID.ToString());

 

        // temp variables

        string prevAttributeName = "";

        string attributeName, attributeValue, attributeValueId;

 

        // current DropDown for attribute values

        Label attributeNameLabel;

        DropDownList attributeValuesDropDown = new DropDownList();

 

        // read the list of attributes

        foreach (DataRow r in attrTable.Rows)

        {

            // get attribute data

            attributeName = r["AttributeName"].ToString();

            attributeValue = r["AttributeValue"].ToString();

            attributeValueId = r["AttributeValueID"].ToString();

 

            // if starting a new attribute (e.g. Color, Size)

            if (attributeName != prevAttributeName)

            {

                prevAttributeName = attributeName;

                attributeNameLabel = new Label();

                attributeNameLabel.Text = attributeName + ": ";

                attributeValuesDropDown = new DropDownList();

                attrPlaceHolder.Controls.Add(attributeNameLabel);

                attrPlaceHolder.Controls.Add(attributeValuesDropDown);

            }

 

            // add a new attribute value to the DropDownList

            attributeValuesDropDown.Items.Add(new ListItem(attributeValue, attributeValueId));

        }

    }

    protected void AddToCartButton_Click(object sender, EventArgs e)

    {

 

        // Retrieve ProductID from the query string

        string productId = Request.QueryString["ProductID"];

        // Retrieves product details

        ProductDetails pd = CatalogAccess.GetProductDetails(productId);

 

        // Retrieve the selected product options

        string options = "";

        foreach (Control cnt in attrPlaceHolder.Controls)

        {

            if (cnt is Label)

            {

                Label attrLabel = (Label)cnt;

                options += attrLabel.Text;

            }

 

            if (cnt is DropDownList)

            {

                DropDownList attrDropDown = (DropDownList)cnt;

                options += attrDropDown.Items[attrDropDown.SelectedIndex] + "; ";

            }

        }

 

        // The Add to Cart link

        string productUrl = Link.ToProduct(pd.ProductID.ToString());

        string destination = Link.ToPayPalAddItem(productUrl, pd.Name, pd.Price, options);

        Response.Redirect(destination);

    }

}
:8351861 |会员

回答

评论会员:游客 时间:2012/02/07
固定链接imgsrc=http://www.orcode.com/img/ico/smiley_smile.gif]
会员8351861:这里是我的web.config文件,让我知道它是确定的。我新的ASP.NET和C#,我真的需要一些帮助。我可以把所有的代码,如果这将有助于?
<?xml version="1.0" encoding="UTF-8"?>

<!--

  For more information on how to configure your ASP.NET application, please visit

  http://go.microsoft.com/fwlink/?LinkId=169433

  -->

<configuration>

  <configSections>

    <section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />

  </configSections>

  <rewriter>

    <!-- Rewrite department pages -->

    <rewrite url="^.*-d([0-9]+)/?$" to=" /Catalog.aspx?DepartmentID=$1" processing="stop" />

    <rewrite url="^.*-d([0-9]+)/page-([0-9]+)/?$" to=" /Catalog.aspx?DepartmentID=$1&amp;Page=$2" processing="stop" />

    <!-- Rewrite category pages -->

    <rewrite url="^.*-d([0-9]+)/.*-c([0-9]+)/?$" to=" /Catalog.aspx?DepartmentId=$1&amp;CategoryId=$2" processing="stop" />

    <rewrite url="^.*-d([0-9]+)/.*-c([0-9]+)/page-([0-9]+)/?$" to=" /Catalog.aspx?DepartmentId=$1&amp;CategoryId=$2&amp;Page=$3" processing="stop" />

    <!-- Rewrite product details pages -->

    <rewrite url="^.*-p([0-9]+)/?$" to=" /Product.aspx?ProductId=$1" processing="stop" />

  </rewriter>

  <appSettings>

    <add key="PaypalUrl" value="https://www.paypal.com/xclick" />

    <add key="PaypalEmail" value="Test@example.com" />

    <add key="PaypalCurrency" value="USD" />

    <add key="PaypalReturnUrl" value="http://www.poshanddangles.com" />

    <add key="PaypalCancelUrl" value="http://www.poshanddangles.com" />

    <add key="MailServer" value="mail server address" />

    <add key="MailUsername" value="mail username " />

    <add key="MailPassword" value="mail password" />

    <add key="MailFrom" value="mail address" />

    <add key="EnableErrorLogEmail" value="false" />

    <add key="ErrorLogEmail" value="errors@example.com" />

    <add key="ProductsPerPage" value="6" />

    <add key="ProductDescriptionLength" value="60" />

    <add key="SiteName" value="PoshandDangles" />

    <add key="CartPersistDays" value="10" />

  </appSettings>

  <connectionStrings>

    <add name="PoshandDanglesConnection" connectionString="Server=(local)\SqlExpress; Database=PoshandDangles; Integrated Security=SSPI" providerName="System.Data.SqlClient" />

    <remove name="LocalSqlServer" />

    <add name="LocalSqlServer" connectionString="Server=(local)\SqlExpress;Database=PoshandDangles; Integrated Security=SSPI" providerName="System.Data.SqlClient" />

  </connectionStrings>

  <location path="AdminDepartments.aspx">

    <system.web>

      <authorization>

        <allow roles="Administrators" />

        <deny users="*" />

      </authorization>

    </system.web>

  </location>

  <location path="AdminCategories.aspx">

    <system.web>

      <authorization>

        <allow roles="Administrators" />

        <deny users="*" />

      </authorization>

    </system.web>

  </location>

  <location path="AdminProducts.aspx">

    <system.web>

      <authorization>

        <allow roles="Administrators" />

        <deny users="*" />

      </authorization>

    </system.web>

  </location>

  <location path="AdminProductDetails.aspx">

    <system.web>

      <authorization>

        <allow roles="Administrators" />

        <deny users="*" />

      </authorization>

    </system.web>

  </location>

  <location path="AdminProductAttributes.aspx">

    <system.web>

      <authorization>

        <allow roles="Administrators" />

        <deny users="*" />

      </authorization>

    </system.web>

  </location>

  <!-- Only administrators are allowed to access ShoppingCartAdmin.aspx -->

  <location path="AdminShoppingCart.aspx">

    <system.web>

      <authorization>

        <allow roles="Administrators" />

        <deny users="*" />

      </authorization>

    </system.web>

  </location>

  <!-- Only administrators are allowed to access AdminOrders.aspx -->

  <location path="AdminOrders.aspx">

    <system.web>

      <authorization>

        <allow roles="Administrators" />

        <deny users="*" />

      </authorization>

    </system.web>

  </location>

  <!-- Only administrators are allowed to access AdminOrders.aspx -->

  <location path="AdminOrderDetails.aspx">

    <system.web>

      <authorization>

        <allow roles="Administrators" />

        <deny users="*" />

      </authorization>

    </system.web>

  </location>

 

  <system.web>

      <webServices>

          <protocols>

              <add name="HttpPost" />

          </protocols>

      </webServices>

 

      <roleManager enabled="true" />

    <globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="en-US" />

    <!--

            Set compilation debug="true" to insert debugging

            symbols into the compiled page. Because this

            affects performance, set this value to true only

            during development.

        -->

    <compilation debug="true" targetFramework="4.0" />

    <!--

            The <authentication> section enables configuration

            of the security authentication mode used by

            ASP.NET to identify an incoming user.

        -->

    <authentication mode="Forms">

      <forms name="PoshandDanglesLogin" loginUrl="Login.aspx" path="/" protection="All" timeout="60" />

    </authentication>

    <!--

            The <customErrors> section enables configuration

            of what to do if/when an unhandled error occurs

            during the execution of a request. Specifically,

            it enables developers to configure html error pages

            to be displayed in place of a error stack trace.

 

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">

            <error statusCode="403" redirect="NoAccess.htm" />

            <error statusCode="404" redirect="FileNotFound.htm" />

        </customErrors>

        -->

    <customErrors mode="Off" defaultRedirect=" /Oops.aspx">

      <error statusCode="404" redirect=" /NotFound.aspx" />

      <error statusCode="500" redirect=" /Oops.aspx" />

    </customErrors>

    <pages theme="PoshandDanglesDefault" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />

    <httpModules>

      <add type="Intelligencia.UrlRewriter.RewriterHttpModule,Intelligencia.UrlRewriter" name="UrlRewriter" />

    </httpModules>

  </system.web>

  <!--

        The system.webServer section is required for running ASP.NET AJAX under Internet

        Information Services 7.0.  It is not necessary for previous version of IIS.

    -->

  <system.webServer>

    <modules runAllManagedModulesForAllRequests="true">

      <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule" />

    </modules>

        <handlers>

            <remove name="PageHandlerFactory-ISAPI-4.0_32bit" />

            <add name="PageHandlerFactory-ISAPI-4.0_32bit" path=".aspx" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />

        </handlers>

  </system.webServer>

</configuration>
评论会员:dpawski 时间:2012/02/07


我有同样的问题,我添加以下重写我的web.config
<rewrite url="^.*-p([0-9]+)/.*=([0-9]+)/?$" to=" /Product.aspx?ProductId=$1" processing="stop" />
它做工精细:拉杰什Anuhya
评论会员:游客 时间:2012/02/07
谢谢你的链接,我看到这个江前,但我使用IIS7的ASP.NET4.0,我是无法找到这个映射asp.isapi.dll:8351861|会员
试试这个代码:
{体C3}我希望它会帮助你。 {S0}