Motley
Motley
CC#
Created by prodijay on 6/21/2024 in #help
Unable to get logged in user with GetUserAsync
Are you running some sort of IdentityServer?
39 replies
CC#
Created by prodijay on 6/21/2024 in #help
Unable to get logged in user with GetUserAsync
This isn't the normal setup that I am used to. Typically for authenticated applications, once a user is authenticated, you can just get the user details like name, email, roles from the HttpContext.User without having to go through any sort of UserManager.
39 replies
CC#
Created by Billy on 6/21/2024 in #help
XML Deserialization
You can fairly easily refactor the code I put above to handle most structures.
28 replies
CC#
Created by Billy on 6/21/2024 in #help
XML Deserialization
I'd start with a class model that you want to actually represent your structure and then ask for help on how to parse the Xml into that structure.
28 replies
CC#
Created by Billy on 6/21/2024 in #help
XML Deserialization
Can node just have a content property that is the of type List<BaseElement>?
28 replies
CC#
Created by Billy on 6/21/2024 in #help
XML Deserialization
Can your book have multiple titles and headers or only one of each?
28 replies
CC#
Created by Billy on 6/21/2024 in #help
XML Deserialization
Try something like this?
public class Book : IXmlSerializable
{
public Header Header { get; set; }
public Title Title { get; set; }

public XmlSchema GetSchema() => null;

public void ReadXml(XmlReader reader)
{
reader.MoveToContent();
int index = 1; // Start index counting

while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element && reader.Name == "Header")
{
Header = new Header { Index = index++ };
Header.ReadXml(reader);
}
else if (reader.NodeType == XmlNodeType.Element && reader.Name == "Title")
{
Title = new Title { Index = index++ };
Title.ReadXml(reader);
}
}
}

public void WriteXml(XmlWriter writer)
{
// Implement serialization logic if needed
}
}

public class Header : BaseElement, IXmlSerializable
{
public string Text { get; set; }

public void ReadXml(XmlReader reader)
{
reader.ReadStartElement("Header");
Text = reader.ReadElementContentAsString("Text", "");
reader.ReadEndElement();
}

public void WriteXml(XmlWriter writer)
{
// Implement serialization logic if needed
}
}
public class Book : IXmlSerializable
{
public Header Header { get; set; }
public Title Title { get; set; }

public XmlSchema GetSchema() => null;

public void ReadXml(XmlReader reader)
{
reader.MoveToContent();
int index = 1; // Start index counting

while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element && reader.Name == "Header")
{
Header = new Header { Index = index++ };
Header.ReadXml(reader);
}
else if (reader.NodeType == XmlNodeType.Element && reader.Name == "Title")
{
Title = new Title { Index = index++ };
Title.ReadXml(reader);
}
}
}

public void WriteXml(XmlWriter writer)
{
// Implement serialization logic if needed
}
}

public class Header : BaseElement, IXmlSerializable
{
public string Text { get; set; }

public void ReadXml(XmlReader reader)
{
reader.ReadStartElement("Header");
Text = reader.ReadElementContentAsString("Text", "");
reader.ReadEndElement();
}

public void WriteXml(XmlWriter writer)
{
// Implement serialization logic if needed
}
}
28 replies
CC#
Created by Billy on 6/21/2024 in #help
XML Deserialization
I think you'd have to use a custom deserializer
28 replies
CC#
Created by Billy on 6/21/2024 in #help
XML Deserialization
That is very not xml like
28 replies
CC#
Created by prodijay on 6/21/2024 in #help
Unable to get logged in user with GetUserAsync
What is UserManager<T>? Is that a class you defined yourself?
39 replies
CC#
Created by Vegas on 6/21/2024 in #help
Connecting to database via String in XML
Glad to help!
55 replies
CC#
Created by Vegas on 6/21/2024 in #help
Connecting to database via String in XML
I had a pre-existing project called "RedboxDressed" that I just shoved that into.
55 replies
CC#
Created by Vegas on 6/21/2024 in #help
Connecting to database via String in XML
Hope that helps
55 replies
CC#
Created by Vegas on 6/21/2024 in #help
Connecting to database via String in XML
No description
55 replies
CC#
Created by Vegas on 6/21/2024 in #help
Connecting to database via String in XML
No description
55 replies
CC#
Created by Vegas on 6/21/2024 in #help
Connecting to database via String in XML
No description
55 replies
CC#
Created by Vegas on 6/21/2024 in #help
Connecting to database via String in XML
No description
55 replies
CC#
Created by Vegas on 6/21/2024 in #help
Connecting to database via String in XML
Then you should have an App.config file in your application and that is where ConfigurationManager expects it to be.
55 replies
CC#
Created by Vegas on 6/21/2024 in #help
Connecting to database via String in XML
Leave the default "App.config" alone at the bottom, and click add
55 replies
CC#
Created by Vegas on 6/21/2024 in #help
Connecting to database via String in XML
No description
55 replies