Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this C# action method code actually firing a 301 redirect?

Here is the code I use when someone visits a product page on my ecommerce website.

public ActionResult Details(int id, string slug)
{
    using (var productRepository = new EfProductRepository())
    {
        var product = productRepository.FindById(id);
        if (product == null) return RedirectToAction("Index", "Home");
        if (product.SeoTextSlug != slug)
            return RedirectToAction("Details", new {id = product.ProductId, slug = product.SeoTextSlug});

        var model = new ProductDetailModel();

        //Load the product information.
        model.Product.ProductId = product.ProductId;
        model.Product.CoverImagePath = product.CoverImagePath;
        model.Product.Name = product.Name;
        model.Product.Tagline = product.Tagline;
        model.Product.Price = product.Price;
        model.Product.Stock = product.Stock;
        model.Product.PieceCount = (int)product.PieceCount;
        model.Product.SKU = product.SKU;

        //Load the reviews for that product.
        if (product.Reviews.Any())
        {
            foreach (var review in product.Reviews)
            {
                model.Reviews.Add(new ReviewModel()
                {
                    ReviewId = review.ReviewId,
                    AccountId = (int)review.AccountId,
                    Content = review.Content,
                    Location = review.Location,
                    ProductId = (int)review.ProductId,
                    PublishDate = review.PublishDate,
                    ReviewRatingId = (int)review.ReviewRatingId
                });   
            }
        }

        return View(model);
    }
}

In this bit:

if (product.SeoTextSlug != slug)
    return RedirectToAction("Details", new {id = product.ProductId, slug = product.SeoTextSlug});

Am I actually firing a 301 redirect correctly?

Sure it's working as I want it to, but I want to make sure I'm returning a correct standard HTTP result so search engines properly respond to it.

like image 714
Only Bolivian Here Avatar asked Apr 05 '12 15:04

Only Bolivian Here


People also ask

What is * this in C?

The expression *this is commonly used to return the current object from a member function: C++ Copy. return *this; The this pointer is also used to guard against self-reference: C++ Copy.

Can you use this in C?

It is not a reserved identifier, so you are free to use it.

What does * this mean in C++?

this means pointer to the object, so *this is an object. So you are returning an object ie, *this returns a reference to the object.

What does |= mean in C?

The bitwise OR assignment operator ( |= ) uses the binary representation of both operands, does a bitwise OR operation on them and assigns the result to the variable.


1 Answers

I believe that RedirectToAction returns 302 while RedirectToActionPermanent returns 301.

like image 57
Wiktor Zychla Avatar answered Sep 22 '22 10:09

Wiktor Zychla